package work3.bus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work3.bus.entity.BusLine;
import work3.bus.service.BusLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/busLine")
public class BusLineController {

    @Autowired
    private BusLineService busLineService;

    // 显示公交线路信息
    @GetMapping("/list")
    public List<BusLine> list() {
        return busLineService.list();
    }

    // 添加公交线路信息
    @PostMapping("/add")
    public boolean add(@RequestBody BusLine busLine) {
        return busLineService.save(busLine);
    }

    // 修改公交线路信息
    @PutMapping("/update")
    public boolean update(@RequestBody BusLine busLine) {
        return busLineService.updateById(busLine);
    }

    // 删除公交线路信息
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable Long id) {
        return busLineService.removeById(id);
    }

    // 根据名称查询公交线路信息
    @GetMapping("/findByName/{lineName}")
    public List<BusLine> findByName(@PathVariable String lineName) {
        QueryWrapper<BusLine> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BusLine::getLineName, lineName);
        return busLineService.list(queryWrapper);
    }

    // 根据线路号查询公交线路信息
    @GetMapping("/findByLineNumber/{lineNumber}")
    public List<BusLine> findByLineNumber(@PathVariable String lineNumber) {
        QueryWrapper<BusLine> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BusLine::getLineNumber, lineNumber);
        return busLineService.list(queryWrapper);
    }
}